package edu.sctu.yueding.adapter;

import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import edu.sctu.yueding.R;
import edu.sctu.yueding.bean.MyTeamMembersBean;

/**
 * Created by fll on 2016/8/19.
 */
public class SignUpMyTeamAdapter extends BaseAdapter {
    Activity activity;
    private List<MyTeamMembersBean> list = new ArrayList<>();

    public SignUpMyTeamAdapter(Activity activity, List<MyTeamMembersBean> list) {
        this.activity = activity;
        this.list = list;
    }

    /**
     * 刷新数据
     *
     * @param data
     */
    public void fresh(List<MyTeamMembersBean> data, boolean isAddAll) {
        if (isAddAll) {
            this.list.addAll(data);
        } else {
            this.list = data;
        }
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            Log.e("list.size", String.valueOf(list.size()));
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(activity).inflate(R.layout.item_sign_up_my_team, null);

        TextView name = (TextView) convertView.findViewById(R.id.sign_up_my_team_name_detail);
        TextView gender = (TextView) convertView.findViewById(R.id.sign_up_my_team_sex_detail);
        TextView idNumber = (TextView) convertView.findViewById(R.id.sign_up_my_team_id_detail);
        TextView phoneNumber = (TextView) convertView.findViewById(R.id.sign_up_my_team_phone_detail);

        name.setText(list.get(position).getRealName());
        gender.setText(list.get(position).getGender());
        idNumber.setText(list.get(position).getIdNumber());
        phoneNumber.setText(list.get(position).getPhoneNumber());

        return convertView;
    }

}
